package com.jsg.sl651.entity.station;

import com.jsg.sl651.entity.city.CityDefinition;
import com.jsg.sl651.util.ChineseCity;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class OtherTelemetryStationAddresses implements RemoteTelemetryStationAddress{

    // 原始报文
    private final String originalMessage;

    // 测站城市信息
    private final CityDefinition cityDefinition;

    // 地址
    private final String address;

    public OtherTelemetryStationAddresses(final String originalMessage) {
        if (originalMessage == null || originalMessage.length() != 10 || originalMessage.startsWith("00")) {
            throw new IllegalArgumentException("originalMessage is null or originalMessage length is not 10 or originalMessage start with 00");
        }
        this.originalMessage = originalMessage;
        this.cityDefinition = ChineseCity.getCityDefinition(originalMessage.substring(0,6));
        this.address = originalMessage.substring(6);
    }

    @Override
    public String getMessageHex() {
        return originalMessage;
    }

    @Override
    public String toString() {
        return "其他遥测站信息{" +
                "原始报文=" + originalMessage + "," +
                "省市=" + cityDefinition.getProvince().getCityName() + "," +
                "城市=" + cityDefinition.getCity().getCityName() + "," +
                "区县=" + cityDefinition.getDistrict().getCityName() + "," +
                "地址=" + address +
                "}";
    }
}
